package com.colorlight.cloud.grandshow.entity.instructions;

import com.colorlight.cloud.grandshow.api.GrandShowEntityScheduleActions;
import com.colorlight.iot.proto.grandshow.instruction.GrandShowInstruction;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.Objects;

/**
 * 解绑设备主体
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Slf4j
public class RemoveDevice implements GrandShowEntityScheduleActions {
    private RemoveDevice.InputMsg input;
    private RemoveDevice.OutputMsg output;

    @Override
    public ByteString objectConvertBytes() {
        final GrandShowInstruction.Decrypt.InputMsg.Builder inputMsg =
                GrandShowInstruction.Decrypt.InputMsg.newBuilder();
        final GrandShowInstruction.Decrypt.Builder builder =
                GrandShowInstruction.Decrypt.newBuilder();
        builder.setInput(inputMsg);
        return builder.build().toByteString();
    }

    @Override
    public RemoveDevice byteConvertObject(ByteString bytes) {
        GrandShowInstruction.RemoveDevice removeDevice = null;
        try {
            removeDevice = GrandShowInstruction.RemoveDevice.parseFrom(bytes);
        } catch (InvalidProtocolBufferException e) {
            log.error("", e);
        }
        Objects.requireNonNull(removeDevice);
        final OutputMsg outputMsg = new OutputMsg();
        this.setOutput(outputMsg);
        return this;
    }

    @Data
    @NoArgsConstructor
    @Builder
    public static class InputMsg implements Serializable {
    }

    @Data
    @NoArgsConstructor
    @Builder
    public static class OutputMsg implements Serializable {
    }
}